<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>DTChat - VCard - </title>
		<meta http-equiv="content-type" content="text/html; charset=utf-8">
		<script src="shared.js"></script>
    <script src="switchStyle.js"></script>
    <script src="xmlextras.js"></script>
    <script src="JSJaCPacket.js"></script>
		<script>
		<!--
		var jid , vcard;
		var srcW; // the source window with necessary data

    function sendSub() {
			var iq = new JSJaCIQ();
			iq.setType('set');

			var vCard = iq.getNode().appendChild(iq.getDoc().createElement('vCard'));
			vCard.setAttribute('xmlns','vcard-temp');

      for (var i=0; i<document.forms[0].elements.length; i++) {
				var item = document.forms[0].elements[i];
        if (item.id == '') continue;
        if (item.value == '' ) continue;
				if (item.id.indexOf('.') != -1) {
					var tagname = item.id.substring(0,item.id.indexOf('.'));
					var aNode;
					if (vCard.getElementsByTagName(tagname).length > 0)
						aNode = vCard.getElementsByTagName(tagname).item(0);
					else
						aNode = vCard.appendChild(iq.getDoc().createElement(tagname));
					aNode.appendChild(iq.getDoc().createElement(item.id.substring(item.id.indexOf('.')+1))).appendChild(iq.getDoc().createTextNode(item.value));
				} else {
					vCard.appendChild(iq.getDoc().createElement(item.id)).appendChild(iq.getDoc().createTextNode(item.value));
				}
			}
			srcW.Debug.log(iq.getDoc().xml,3);
			srcW.con.syncSend(iq);
      window.close();
    }

    function init() {
      srcW = opener.top;

      getArgs();

      jid = passedArgs['jid'];
      document.title += jid;
  
      for (var i=0; i<document.forms[0].elements.length;i++) {
        if (document.forms[0].elements[i].id == '') continue;
        if (cutResource(jid) != srcW.cutResource(srcW.jid)) {
          document.forms[0].elements[i].className = "vcardBox";
          document.forms[0].elements[i].readOnly = true;
        }
      }

      if (cutResource(jid) != srcW.cutResource(srcW.jid))
        document.getElementById("savebox").style.display = 'none';

			// request vcard

			var iq = new JSJaCIQ();
			iq.setType('get');
      if (cutResource(jid) != srcW.cutResource(srcW.jid)) // not me
				iq.setTo(jid);
			var vCard = iq.getNode().appendChild(iq.getDoc().createElement('vCard'));
			vCard.setAttribute('xmlns','vcard-temp');
			me = this;
			srcW.con.send(iq,me.handleVCard);
    }

		function handleVCard(iq) {
			if (!iq) {
				srcW.Debug.log('got empty iq result',1);
				return;
			}

			srcW.Debug.log(iq.getDoc().xml,3);

			if (iq.getNode().getElementsByTagName('vCard').item(0)) {
				for (var i=0; i<iq.getNode().getElementsByTagName('vCard').item(0).childNodes.length; i++) {
					var token = iq.getNode().getElementsByTagName('vCard').item(0).childNodes.item(i);
					tokenname = token.nodeName;
					if (token.firstChild && token.firstChild.nodeType != 3) { // found a container
						for (var j=0; j<token.childNodes.length; j++) {
							if (typeof(document.forms[0].elements[tokenname+"."+token.childNodes.item(j).nodeName]) != 'undefined' && token.childNodes.item(j).firstChild)
								document.forms[0].elements[tokenname+"."+token.childNodes.item(j).nodeName].value = token.childNodes.item(j).firstChild.nodeValue;
						}

					} else
						if (typeof(document.forms[0].elements[tokenname]) != 'undefined' && token.firstChild)
							document.forms[0].elements[tokenname].value = token.firstChild.nodeValue;
				}
			}
		}

		function keyPressed(e) {
			if (e.keyCode == 27)
				window.close();
		}
		onkeydown = keyPressed;
		onload = init;
		//-->
		</script>
		<script for="document" event="onkeydown()" language="JScript">
		<!--
			if (window.event.keyCode == 27)
				window.close();
		//-->
		</script>
    <style type="text/css">
      <!--
      th { 
      font-family: sans-serif;
      font-size: 12px;
      text-align: right;
      }
      // -->
    </style>
	</head>
	<body style="margin:8px">
    <form>
    <fieldset>
      <legend>Name</legend>
      <table>
          <tr><th nowrap>Full Name:</th><td width="100%"><input type=text id="FN" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>Family Name:</th><td width="100%"><input type=text id="N.FAMILY" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>Name:</th><td width="100%"><input type=text id="N.GIVEN" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>Nickname:</th><td width="100%"><input type=text id="NICKNAME" class="vcardBoxEditable"></td></tr>
      </table>
    </fieldset>
    
    <fieldset>
      <legend>Information</legend>
      <table>
          <tr><th nowrap>E-mail:</th><td width="100%"><input type=text id="EMAIL" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>Web Site:</th><td width="100%"><input type=text id="URL" class="vcardBoxEditable"></td></tr>
      </table>
    </fieldset>
    
    <fieldset>
      <legend>Address</legend>
      <table>
          <tr><th nowrap>Address:</th><td width="100%"><input type=text id="ADR.STREET" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>Address2:</th><td width="100%"><input type=text id="ADR.EXTADD" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>City:</th><td width="100%"><input type=text id="ADR.LOCALITY" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>State:</th><td width="100%"><input type=text id="ADR.REGION" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>Postal Code:</th><td width="100%"><input type=text id="ADR.PCODE" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>Country:</th><td width="100%"><input type=text id="ADR.CTRY" class="vcardBoxEditable"></td></tr>
      </table>
    </fieldset>

    <fieldset>
      <legend>Organization</legend>
      <table>
          <tr><th nowrap>Name:</th><td width="100%"><input type=text id="ORG.ORGNAME" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>Unit:</th><td width="100%"><input type=text id="ORG.ORGUNIT" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>Title:</th><td width="100%"><input type=text id="TITLE" class="vcardBoxEditable"></td></tr>
          <tr><th nowrap>Role:</th><td width="100%"><input type=text id="ROLE" class="vcardBoxEditable"></td></tr>
      </table>
    </fieldset>

    <fieldset>
      <legend>About</legend>
      <table width="100%">
          <tr><th>Birthday:</th><td width="100%"><input type=text id="BDAY" class="vcardBoxEditable"></td></tr>
		<tr><td colspan=2>&nbsp;</td></tr>
          <tr><th>Description:</th><td width="100%">&nbsp;</td></tr>
          <tr><td colspan=2 width="100%"><textarea id="DESC" class="vcardBoxEditable" style="width:100%;" rows=4 wrap=virtual></textarea></td></tr>
      </table>
    </fieldset>
    <div id="savebox">
		<hr noshade size="1" size="100%">
		<div align="right">
			<button onClick="window.close();">Cancel</button>&nbsp;<button onClick="return sendSub();">Save</button>
		</div>
      </div>
    </form>
	</body>
</html>
